#include<iostream>
#include<cstdio>
#include<algorithm>

#define rep(i,a,b) for(register int i=(a);i<=(b);i++)

using namespace std;

const int MAXN=55555;

struct Edge{
	int left;
	int right;
	bool operator<(const Edge y)const
	{ 
		return left<y.left;
	}
}a[MAXN];

inline int max(int cyh,int mxy){return cyh>mxy?cyh:mxy;}

int main()
{
	int n;
	cin>>n;
	rep(i,1,n)
		cin>>a[i].left>>a[i].right;
	stable_sort(a+1,a+n+1);
	int left=a[1].left,right=a[1].right;
	rep(i,2,n)
	{
		if(a[i].left<=right)
			right=max(a[i].right,right);
		else
		{
			cout<<left<<" "<<right<<endl;
			left=a[i].left,right=a[i].right;
		}
	}
	cout<<left<<" "<<right;
	return 0;
}